with Parser;                      use Parser;
with Tipus;                       use Tipus;
with Ada.Text_IO;                 use Ada.Text_IO;
with Ada.Integer_Text_IO;         use Ada.Integer_Text_IO;
with Ada.Strings.Unbounded;       use Ada.Strings.Unbounded;
with Ada.Numerics.Float_Random;   use Ada.Numerics.Float_Random;



procedure Main is

   -- Vars. Globals
   Vector_Nodes: PTR_Array_Nodes;
   Nom_Fitxer : constant Unbounded_String := To_Unbounded_String("zachary.net");
   Nom_Fitxer_Length : constant Integer := 11;
   Recovery_Rate : constant Float := 0.1;
   Infection_Rate: constant Float := 0.1; --me l'acabo d'inventar
   Contact_Cardinality : constant Integer := 1;
   Probabilitat_Infeccio_Inicial : constant Float := 0.2;
   T_Trans : constant Integer := 100;
   T_Est : constant Integer := 50;
   N_Reps : constant Integer := 50;
   Gen : Ada.Numerics.Float_Random.Generator;
   Deu : PTR_God;



   procedure Imprimir(V: PTR_Array_Nodes) is
      E:Integer;
   begin
      for I in 1..V'Length loop
         Put("Node " & Integer'Image(i) & " => Llista de connexions: { ");
         Int_Linked_Lists.Save(V(I).Llista_Connexions);
         Int_Linked_Lists.Reset(V(I).Llista_Connexions);
         while Int_Linked_Lists.Has_Next(V(I).Llista_Connexions) loop
            E := Int_Linked_Lists.Next(V(I).Llista_Connexions);
            Put(E, Width => 0); Put(" ");
         end loop;
         Int_Linked_Lists.Restore(V(I).Llista_Connexions);
         Put("}"); New_Line;
      end loop;
   end Imprimir;

begin

   --Inicialitzacions
   Reset(Gen);
   Deu := new God;


   -- Imprimir parametres del SIS
   New_Line;
   Put_Line("-------------- Parametres del SIS -----------------");
   Put_Line("Recovery_Rate = " & Float'Image(Recovery_Rate));
   Put_Line("Infection_Rate = " & Float'Image(Infection_Rate));
   Put_Line("Contact_Cardinality = " & Integer'Image(Contact_Cardinality));
   Put_Line("Probabilitat_Infeccio_Inicial = " & Float'Image(Probabilitat_Infeccio_Inicial));
   Put_Line("T_Trans = " & Integer'Image(T_Trans));
   Put_Line("T_Est = " & Integer'Image(T_Est));
   Put_Line("N_Reps = " & Integer'Image(N_Reps));
   Put_Line("---------------------------------------------------"); New_Line;

   Parser.Set_File_Name(To_String(Nom_Fitxer), Nom_Fitxer_Length);
   --Omplir id, nom i llista de connexions
   Parser.Read_Pajek_File(Vector_Nodes);
   Imprimir(Vector_Nodes);
   Put_Line("---------------------------------------------------"); New_Line;

   for I in 1..Vector_Nodes'Length loop
      Vector_Nodes(I).Rec_Rate := Recovery_Rate;
      Vector_Nodes(I).Inf_Rate := Infection_Rate;
      Vector_Nodes(I).Cont_Cardinality := Contact_Cardinality;
      Vector_Nodes(I).Prob_Inf_Inicial := Probabilitat_Infeccio_Inicial;
      --Inicialitzar l'estat inicial
      if Random(Gen) > Probabilitat_Infeccio_Inicial then
         Vector_Nodes(I).Estat := Susceptible;
      else
         Vector_Nodes(I).Estat := Infectat;
      end if;
      --Aqui tambe crear tasques i passar parametres
      Vector_Nodes(I).Tasca_Sender := new Sender;
      Vector_Nodes(I).Tasca_Receiver := new Receiver;
      Vector_Nodes(I).Tasca_Sender.Rebre_Punter_Deu(Deu);
      Vector_Nodes(I).Tasca_Receiver.Rebre_Punter_Deu(Deu);
   end loop;
   
   Deu.Rebre_Parametres(Vector_Nodes, T_Trans, T_Est, N_Reps);


end Main;
